package com.cn.lyl.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.lyl.util.Tool;
import com.cn.lyl.util.Upload;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


@WebServlet("/upload")
public class UploadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        Upload.file(req);
        String imgHref = Tool.stringIsNotNull(req.getAttribute("imgHref"));
        //req.getSession().setAttribute("imgHref",imgHref);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("img",imgHref);
        System.out.println(imgHref);
        resp.getWriter().print(jsonObject);
    }
}

